home *** CD-ROM | disk | FTP | other *** search
-
- #include "BuildControl.h"
-
-
-
- #if defined(qUseDumpFile)
- #include "DumpHeader.h"
- #else
- #include <Resources.h>
- #endif
-
- enum {
- kFloaterPopup1 = 128,
- kFloaterPopup2 = 129,
- kFloaterPopup3 = 130,
- kFloaterPopup4 = 131,
-
- kFloatingWindowType1 = 'FlWn'
- };
-
- struct FloatWindowInfo {
- Boolean lastVisibleState;
- ControlHandle geometryPopup;
- ControlHandle controlsPopup;
- ControlHandle rendererPopup;
- ControlHandle otraPopup;
- };
-
- typedef struct FloatWindowInfo FloatWindowInfo,
- *FloatWindowInfoPtr, **FloaterInfoHndl;
-
-
- #include "WindowObj.h"
- #include "MainWindow.h"
- #include "Quickdraw3DSupport.h"
- #include "FloatingWindowSupport.h"
-
- void FloatWindowDraw(WindowObjHndl obj, short depth);
- void FloatWindowClick(WindowObjHndl obj, EventRecord *event, long message);
- void FloatWindowActivate(WindowObjHndl obj, Boolean activate);
- void FloatWindowKeys(WindowObjHndl obj, long message, short mods);
- void FloatWindowNotify(WindowObjHndl obj, long message);
-
- Boolean GetLastVisibleState(WindowPtr);
- void SetLastVisibleState(WindowPtr, Boolean);
-
- void OpenFloatWindow(void);
- void DeleteAllItems(MenuHandle menu);
- void BuildPopup1(ControlHandle cntl);
-
- void CreatePopupFloater(WindowObjHndl obj);
-
-
- WindowObjHndl pPopupFloater = NULL;
-
- //-----------------------------------------------------------------------
- // A quick cheesy way to test that two different floaters works, too.
- //-----------------------------------------------------------------------
- void OpenFloatWindow()
- {
- if (pPopupFloater == NULL)
- pPopupFloater = NewObjWindow(130, kFloatingWindowType1, true, true,
- FloatWindowDraw, FloatWindowKeys, FloatWindowClick,
- FloatWindowActivate, FloatWindowNotify);
- else
- ShowThisWindow((*pPopupFloater)->window);
-
- }
-
- //-----------------------------------------------------------------------
-
- void DeleteAllItems(MenuHandle menu)
- {
- short items, count;
-
- items = CountMItems(menu);
-
- for (count = 0; count < items; count ++)
- DeleteMenuItem(menu, 1);
- }
-
- //-----------------------------------------------------------------------
-
- void BuildPopup1(ControlHandle cntl)
- {
- MenuHandle menu;
- PopupPrivateDataHandle popupData;
- short index, maxItems = 4;
- Str255 strList[4] ={ "\pPopup1Item1", "\pPopup1Item2",
- "\pPopup1Item3", "\pPopup1Item4"};
-
- index = 1;
- popupData = (PopupPrivateDataHandle)(*cntl)->contrlData;
- menu = (*popupData)->mHandle;
- DeleteAllItems(menu);
-
- for (index = 1; index <= maxItems; index ++)
- InsertMenuItem(menu, strList[index - 1], index);
-
- (*cntl)->contrlMax = maxItems;
- (*cntl)->contrlMin = 1;
- (*cntl)->contrlValue = 0;
- }
-
- //-----------------------------------------------------------------------
-
- void CreatePopupFloater(WindowObjHndl obj)
- {
- FloaterInfoHndl info;
- ControlHandle cntl1, cntl2, cntl3, cntl4;
- WindowPtr win;
-
- TextSize(9);
- win = (*obj)->window;
-
- info = (FloaterInfoHndl) NewHandle(sizeof(FloatWindowInfo));
- require(info != NULL, InfoAllocFailed);
-
- cntl1 = cntl2 = cntl3 = cntl4 = NULL;
- cntl1 = GetNewControl(kFloaterPopup1, win);
- cntl2 = GetNewControl(kFloaterPopup2, win);
- cntl3 = GetNewControl(kFloaterPopup3, win);
- cntl4 = GetNewControl(kFloaterPopup4, win);
-
- require(((cntl1 != NULL) && (cntl2 != NULL)
- && (cntl3 != NULL) && (cntl4 != NULL)), PopupAllocFailed);
-
- // BuildPopup1(cntl1);
-
- SetCtlValue(cntl1, 1); ShowControl(cntl1);
- SetCtlValue(cntl2, 1); ShowControl(cntl2);
- SetCtlValue(cntl3, 1); ShowControl(cntl3);
- SetCtlValue(cntl4, 1); ShowControl(cntl4);
-
- (*info)->geometryPopup = cntl1;
- (*info)->controlsPopup = cntl2;
- (*info)->rendererPopup = cntl3;
- (*info)->otraPopup = cntl4;
- (*info)->lastVisibleState = false;
- (*obj)->refCon = (unsigned long) info;
-
- PopupAllocFailed:
- InfoAllocFailed:
- return;
- }
-
- //-----------------------------------------------------------------------
-
- void FloatWindowNotify(WindowObjHndl obj, long message)
- {
- FloaterInfoHndl info;
-
- switch (message) {
- case kIdleNotification:
- break;
-
- case kCloseNotification:
- break;
-
- case kCreateNotification:
- CreatePopupFloater(obj);
- break;
-
- case kDestroyNotification:
- {
- info = (FloaterInfoHndl) (*obj)->refCon;
-
- if (info != NULL)
- DisposeHandle((Handle) info);
- }
- break;
-
- case kAdjustMenusNotification:
- {
- MenuHandle fileMenu = GetMenuHandle(kFileMenu),
- editMenu = GetMenuHandle(kEditMenu);
-
- if (fileMenu != NULL) {
- EnableAllMenuItems(fileMenu);
- DisableItem(fileMenu, kNewItem);
- }
-
- if (editMenu != NULL) {
- EnableAllMenuItems(editMenu);
- DisableItem(editMenu, kUndoItem);
- }
- }
- break;
- }
- }
-
- //-----------------------------------------------------------------------
-
- void FloatWindowClick(WindowObjHndl obj, EventRecord *event, long message)
- {
- Point localPt;
- ControlHandle cntl;
- short menuItem;
- WindowPtr win = (*obj)->window;
- FloaterInfoHndl info;
-
- info = (FloaterInfoHndl) (*obj)->refCon;
-
- if (message == inContent) {
- localPt = event->where;
- GlobalToLocal(&localPt);
- (void) FindControl(localPt, win, &cntl);
-
- if (cntl != NULL) {
- WindowPtr threeDeeWindow;
-
- (void) TrackControl(cntl, localPt, (ControlActionUPP) -1);
-
- threeDeeWindow = FrontNonFloatingWindow();
-
- if ((threeDeeWindow != NULL) && (Is3DWindow(threeDeeWindow))) {
- menuItem = GetControlValue(cntl);
-
- if (cntl == (*info)->geometryPopup)
- SetWindowGeometry(threeDeeWindow, menuItem);
-
- else if (cntl == (*info)->controlsPopup)
- SetWindowShading(threeDeeWindow, menuItem);
-
- else if (cntl == (*info)->rendererPopup) {
- PopupPrivateDataHandle priv;
-
- priv = (PopupPrivateDataHandle) (*cntl)->contrlData;
- SetWindowRenderer( threeDeeWindow, menuItem );
- }
- }
- }
- }
- }
-
- //-----------------------------------------------------------------------
-
- void FloatWindowKeys(WindowObjHndl obj, long message, short mods)
- {
- #pragma unused (mods, obj)
- short code = (message & charCodeMask) & 0xFF;
- }
-
- //-----------------------------------------------------------------------
-
- void FloatWindowActivate(WindowObjHndl obj, Boolean activate)
- {
- #pragma unused (activate, obj)
- }
-
- //-----------------------------------------------------------------------
-
- void FloatWindowDraw(WindowObjHndl obj, short depth)
- {
- #pragma unused (depth)
- WindowPtr win;
-
- win = (*obj)->window;
- UpdateControls(win, win->visRgn);
-
- ForeColor(blackColor);
- MoveTo(5, 15);
-
- if ((*obj)->type == kFloatingWindowType1)
- DrawString("\pFloat 1");
- }
-
- //-----------------------------------------------------------------------
-
- Boolean GetLastVisibleState(WindowPtr win)
- {
- FloaterInfoHndl info;
- WindowObjHndl obj;
-
- require(IsAppWindow(win), NotAnAppWindow);
-
- obj = (WindowObjHndl) GetWRefCon(win);
- require(obj != NULL, WindowObjHndlIsNULL);
-
- info = (FloaterInfoHndl) (*obj)->refCon;
- require(info != NULL, FloaterInfoHndlIsNULL);
-
- return (*info)->lastVisibleState;
-
- //
- // If we got here, something went terribly wrong
- //
- FloaterInfoHndlIsNULL:
- WindowObjHndlIsNULL:
- NotAnAppWindow:
- return false;
- }
-
- //-----------------------------------------------------------------------
-
- void SetLastVisibleState(WindowPtr win, Boolean visible)
- {
- FloaterInfoHndl info;
- WindowObjHndl obj;
-
- require(IsAppWindow(win), NotAnAppWindow);
-
- obj = (WindowObjHndl) GetWRefCon(win);
- require(obj != NULL, WindowObjHndlIsNULL);
-
- info = (FloaterInfoHndl) (*obj)->refCon;
- require(info != NULL, FloaterInfoHndlIsNULL);
- (*info)->lastVisibleState = visible;
-
- FloaterInfoHndlIsNULL:
- WindowObjHndlIsNULL:
- NotAnAppWindow:
- return;
- }
-